package cn.ccit.servers;

import java.util.List;
import java.util.Map;

import cn.ccit.DAO.UserDAO;
import cn.ccit.DAOImp.UserDAOimp;
import cn.ccit.base.BaseConstants;
import cn.ccit.entites.User;
import cn.ccit.entites.record.UserLoginRecord;
import cn.ccit.iservers.IUserLoginRecordServers;
import cn.ccit.iservers.IUserServers;
import cn.ccit.util.ConstantsUtil;

public class UserServers implements IUserServers{
	private UserDAO userDAO=null;
	private IUserLoginRecordServers userLoginRecord =null;
	private int authorityIdList=0;
	private UserLoginRecord ulr =null;
	private Map<String, String> timeMap=null;
	public UserServers() {
		userDAO=new UserDAOimp();
		userLoginRecord =new UserLoginRecordServers();
	}
	
	@Override
	public boolean regUser(User user) {
		timeMap=ConstantsUtil.getNowTimeMap();
		user.setRoleId(authorityIdList);//设置初始权限列表
		user.setRoleName(BaseConstants.WAITER);
	    user.setCreatTime(timeMap.get(BaseConstants.DATE));
	    user.setLastModfiyTime(timeMap.get(BaseConstants.DATE));
		ulr =new UserLoginRecord();
		ulr.setUname(user.getName());
		return userDAO.regUser(user);
	}

	@Override
	public User loginUser(User user) {
		User u=userDAO.loginUser(user);
		ulr =new UserLoginRecord();
		ulr.setUname(u.getName());
		ulr.setUid(u.getId());
		ulr.setName("登录记录");
		ulr.setTid(u.getTid());
		ulr.setTname(u.getTname());
		userLoginRecord.addUserLoginRecord(ulr);
		return u;
	}

	@Override
	public boolean changePwd(User user) {
		timeMap=ConstantsUtil.getNowTimeMap();
		user.setLastModfiyTime(timeMap.get(BaseConstants.DATE));
		return userDAO.changePwd(user);
	}

	@Override
	public boolean changeUserInfo(User user) {
		timeMap=ConstantsUtil.getNowTimeMap();
		user.setLastModfiyTime(timeMap.get(BaseConstants.DATE));
		return userDAO.changeUserInfo(user);
	}

	@Override
	public boolean setUserAuthorities(User user) {
		return userDAO.changeUserInfo(user);
	}

	@Override
	public boolean setUserTerminal(User user) {
		return userDAO.changeUserInfo(user);
	}

	@Override
	public List<User> getSomeUsers(int startId, int limit) {
		return userDAO.getSomeUsers(startId, limit);
	}

	@Override
	public User searchUserInfoByID(int id) {
		return userDAO.searchUserInfoByID(id);
	}

	@Override
	public List<User> searchUserInfoByName(String name) {
		return userDAO.searchUserInfoByName(name);
	}

	@Override
	public int getAuthorityIdList() {
		return authorityIdList;
	}

	@Override
	public void setAuthorityIdList(int authorityIdList) {
		this.authorityIdList=authorityIdList;
	}

	@Override
	public boolean removeUser(User user) {
		
		return userDAO.removeUser(user);
	}
	
	
}
